//
//  @ Project : Galaxy Star Trading System
//  @ File Name : SettleHelper.h
//  @ Date : 2014/9/5
//  @ Author :
//
//

#if !defined(_CSETTLEHELPER_H_H)
#define _CSETTLEHELPER_H_H

#include "DataBase.h"

namespace GSTrader
{
	namespace TradeService
	{
		class CSettleHelper
		{
		public:
			CSettleHelper(CDataBase* pDataBase);
			virtual ~CSettleHelper();

			void	UpdateUserProfit(int nProviderId);
			double	GetMarginPrice(int nCalcType, CInstrument* pInstrment, double dDefaultPrice, double dAvePrice);


			double	CalcPositionDetailProfit(PositionDetailCursor& pPositionDetail, CAccountInstrument* pAccountInstrment);
			double	CalcPositionProfit(PositionCursor& pPosition, CAccountInstrument* pAccountInstrment);
			double	CalcPositionDetailMargin(PositionDetailCursor& pPositionDetail, CAccountInstrument* pAccountInstrment);
			double	CalcFutureMargin(int nLongShort, int nOpenClose, CAccountInstrument* pAccountInstrment, double dPrice, double dVolTotal);
			double	CalcOptionMargin(int nLongShort, int nOpenClose, CAccountInstrument* pAccountInstrment, double dPrice, double dVolTotal);
			double  CalcCommission(int nProviderId, CAccountInstrument* pAccountInstrment, double dPrice, double dVol, int nOpenClose);
			double  CalcMargin(int nCalcType, int nLongShort, CAccountInstrument* pAccountInstrment, double dPrice, double dVol, int nOpenClose, double dAvePrice = 0);
			double  CalcPremium();

			//frozen
			void	CalcFrozenOrder(int nCalcType, COrderTable& order, CAccountInstrument* pAccountInstrment);
			double  CalcFrozenMargin(int nCalcType, COrderTable& order, CAccountInstrument* pAccountInstrment);
			double  CalcFrozenCommission(COrderTable& order, CAccountInstrument* pAccountInstrment);
			double  CalcFrozenPremium(COrderTable& order, CAccountInstrument* pAccountInstrment);
			void	CalcFroZen(AccountDataCursor& pAccount, bool bCalc);
			//
			double  CalcMargin(int nCalcType, CTradeTable* pTrade, CAccountInstrument* pAccountInstrment);

		private:
			CDataBase* m_pDataBase;
			CDBCommon* m_pDBCommon;

			friend class CDataBase;
		};
	}
}

#endif //_CSETTLEHELPER_H_H